class KeyDeal {
	keyD = null;
	private context:Main;
	public constructor(context:Main) {
       this.context = context;
		/**
		 * 键盘按下事件处理
		 */
		var keynum = null;
		this.keyD = (function () {
			var listener = document;
			var list = [];
			listener.addEventListener("keydown", function (e) {
				if (window.event) // IE
				{
					keynum = e.keyCode
				} else if (e.which) // Netscape/Firefox/Opera
				{
					keynum = e.which
				}
				if (list[keynum])
					list[keynum].call();
			});
			return {
				addEvent: function (_key, fn) {
					list[_key] = fn;
				}
			}
		} ());
		this.addKeyDownList();
	}

	/**
	 *  _key 键盘的_key,
	 *  fn 相应的键盘回调时间
	 */
	public addKeyDownEvent(_key, fn) {
		this.keyD.addEvent(_key, fn);
	}
	/**
	 * 根据相关的key列表创建相应的事件
	 */
	public addKeyDownList() {
		var point = this;
		/**
	 * 关闭所有的子页面
	 */
		this.addKeyDownEvent(27, function () {
			point.context.closeChildPanle();
		});
        /**
         * 音量控制
         */
		this.addKeyDownEvent(86, function () {
			point.context.mainPanel.soundctr.ishasSound();
		});
        /**
         * 控制赔付表
         */
		this.addKeyDownEvent(80, function () {
			if (point.context.contains(point.context.childPanle) && point.context.childPanle.name == "paylist") {
			    point.context.closeChildPanle();
			} else {
			    point.context.mainPanel.openNewchildPanle("paylist");
			}
		});
        /**
         * 控制注数
         */
		this.addKeyDownEvent(37, function () {
			point.context.mainPanel.crystalPanle.cur_zhu.lastNum();
		});
		this.addKeyDownEvent(39, function () {
			point.context.mainPanel.crystalPanle.cur_zhu.nextNum();
		});
        /**
         * 控制旋转
         */
		this.addKeyDownEvent(32, function () {
			if (point.context.mainPanel.gunDeal.gunSigal == 1) {
			    point.context.mainPanel.gunDeal.gunStop();
			} else {
			    point.context.mainPanel.gunDeal.gunRotate();
			}
		});

		this.addKeyDownEvent(65, function () {
			if (point.context.mainPanel.gunDeal.gunSigal == 1) {
			    point.context.mainPanel.gunDeal.gunStop();
			    point.context.mainPanel.crystalPanle.setAutoRotateDisplay();
//				console.log("关闭99");
			} else {
//				console.log("打开99");
			    point.context.mainPanel.gunDeal.gunStop();
			    point.context.mainPanel.gunDeal.gunNumRotate(99);
			}
		});

		/**
		  * 控制投注乘数
		  */
		this.addKeyDownEvent(40, function () {
			point.context.mainPanel.crystalPanle.cur_multiple.lastNum();
		});
		this.addKeyDownEvent(38, function () {
			point.context.mainPanel.crystalPanle.cur_multiple.nextNum();
		});
	}
}